package refactortips.editors.codeSmells;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

import refactortips.editors.AbstractRefactorTipsEditor;
import refactortips.editors.CommandMouseAdapter;

public class LongMethodEditor extends AbstractRefactorTipsEditor {

	protected final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	
	public LongMethodEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		Form frmCodeSmell = formToolkit.createForm(parent);
		formToolkit.paintBordersFor(frmCodeSmell);
		frmCodeSmell.setText("Long Method");
		frmCodeSmell.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(frmCodeSmell.getBody(), SWT.NONE);
		formToolkit.adapt(tabFolder);
		formToolkit.paintBordersFor(tabFolder);
		
		ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc.setExpandHorizontal(true);
	    sc.setExpandVertical(true);
		
		TabItem tbtmDescription = new TabItem(tabFolder, SWT.NONE);
		tbtmDescription.setText("Descri\u00E7\u00E3o");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmDescription.setControl(scrolledComposite);
		formToolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
		formToolkit.adapt(composite_3);
		formToolkit.paintBordersFor(composite_3);
		composite_3.setLayout(null);
		
		Label lblDescription = new Label(composite_3, SWT.NONE);
		lblDescription.setBounds(10, 10, 102, 25);
		lblDescription.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblDescription.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		formToolkit.adapt(lblDescription, true, true);
		lblDescription.setText("Descri\u00E7\u00E3o");
		
		Label lblImageDontRepeat = new Label(composite_3, SWT.NONE);
		lblImageDontRepeat.setImage(ResourceManager.getPluginImage("RefactorTips", "images/codeSmells/longMethod.png"));
		lblImageDontRepeat.setBounds(61, 61, 317, 513);
		formToolkit.adapt(lblImageDontRepeat, true, true);
		
		Link linkExtractMethod1 = new Link(composite_3, SWT.NONE);
		linkExtractMethod1.setBounds(469, 466, 104, 21);
		linkExtractMethod1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkExtractMethod1.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.extractMethodCommand"));
		formToolkit.adapt(linkExtractMethod1, true, true);
		linkExtractMethod1.setText("<a>Extract Method</a>");
		
		Link linkExtractMethod2 = new Link(composite_3, 0);
		linkExtractMethod2.setText("<a>Extract Method</a>");
		linkExtractMethod2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkExtractMethod2.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.extractMethodCommand"));
		linkExtractMethod2.setBounds(342, 615, 104, 21);
		formToolkit.adapt(linkExtractMethod2, true, true);
		
		Link linkReplaceTempWithQuery = new Link(composite_3, 0);
		linkReplaceTempWithQuery.setText("<a>Replace Temp with Query</a>");
		linkReplaceTempWithQuery.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkReplaceTempWithQuery.setBounds(217, 656, 178, 21);
		formToolkit.adapt(linkReplaceTempWithQuery, true, true);
		
		Link linkIntroduceParameterObject = new Link(composite_3, 0);
		linkIntroduceParameterObject.setText("<a>Introduce Parameter Object</a>");
		linkIntroduceParameterObject.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkIntroduceParameterObject.setBounds(163, 677, 191, 21);
		formToolkit.adapt(linkIntroduceParameterObject, true, true);
		
		Link linkPreserveWholeObject = new Link(composite_3, 0);
		linkPreserveWholeObject.setText("<a>Preserve Whole Object</a>");
		linkPreserveWholeObject.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkPreserveWholeObject.setBounds(384, 677, 158, 21);
		formToolkit.adapt(linkPreserveWholeObject, true, true);
		
		Link linkReplaceMethodWithMethodObject = new Link(composite_3, 0);
		linkReplaceMethodWithMethodObject.setText("<a>Replace Method with Method Object</a>");
		linkReplaceMethodWithMethodObject.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkReplaceMethodWithMethodObject.setBounds(119, 728, 253, 21);
		formToolkit.adapt(linkReplaceMethodWithMethodObject, true, true);
		
		Link linkDecomposeConditional = new Link(composite_3, 0);
		linkDecomposeConditional.setText("<a>Decompose Conditional</a>");
		linkDecomposeConditional.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkDecomposeConditional.setBounds(519, 856, 166, 21);
		formToolkit.adapt(linkDecomposeConditional, true, true);
		
		StyledText styledText = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText.setEnabled(false);
		styledText.setDoubleClickEnabled(false);
		styledText.setJustify(true);
		styledText.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText.setText("\t\tOs softwares que tem a melhor vida e vivem por mais tempo s\u00E3o aqueles com m\u00E9todos curtos. Desde os prim\u00F3rdios da programa\u00E7\u00E3o, pessoas perceberam que qu\u00E3o maior (mais linhas de c\u00F3digo) for o m\u00E9todo, mais dif\u00EDcil \u00E9 de entend\u00EA-lo. Outro ponto importante para facilitar o entendimento de m\u00E9todos pequenos \u00E9 dar bons nomes para estes. Se um m\u00E9todo possui um bom nome, voc\u00EA n\u00E3o precisa olhar para o corpo do mesmo. Sempre que sentimos a necessidade de comentar algo, devemos criar um m\u00E9todo ao inv\u00E9s disso.");
		styledText.setBounds(457, 114, 435, 196);
		formToolkit.adapt(styledText);
		formToolkit.paintBordersFor(styledText);
		
		StyledText styledText_1 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_1.setText("\t\tDevemos fazer isso ainda que a chamada do m\u00E9todo seja maior que o c\u00F3digo que este substitui, dado que o nome do m\u00E9todo explica o prop\u00F3sito do c\u00F3digo. O importante n\u00E3o \u00E9 o tamanho do m\u00E9todo mas dist\u00E2ncia sem\u00E2ntica entre o que o m\u00E9todo faz e como ele faz.");
		styledText_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_1.setEnabled(false);
		styledText_1.setJustify(true);
		styledText_1.setDoubleClickEnabled(false);
		styledText_1.setBounds(457, 319, 435, 113);
		formToolkit.adapt(styledText_1);
		formToolkit.paintBordersFor(styledText_1);
		
		StyledText styledText_2 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_2.setText("\t\t99% das vezes, tudo o que voc\u00EA precisa fazer \u00E9 \t\t\t\t\t\t\t. Encontre as partes do m\u00E9todo que aparentam ficar bem juntas e fa\u00E7a um novo m\u00E9todo.");
		styledText_2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_2.setEnabled(false);
		styledText_2.setJustify(true);
		styledText_2.setDoubleClickEnabled(false);
		styledText_2.setBounds(457, 444, 435, 69);
		formToolkit.adapt(styledText_2);
		formToolkit.paintBordersFor(styledText_2);
		
		StyledText styledText_3 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_3.setText("\t\tSe voc\u00EA tem um m\u00E9todo com muitos par\u00E2metros e vari\u00E1veis tempor\u00E1rias, esses elementos ficam no caminho de extrair m\u00E9todos. Se voc\u00EA tentar usar\t\t\t\t\t\t\t\t, voc\u00EA acaba passando tantos dos par\u00E2metros e vari\u00E1veis tempor\u00E1rias como par\u00E2metros para o m\u00E9todo extra\u00EDdo que o resultado \u00E9 dificilmente mais leg\u00EDvel que o original. Voc\u00EA geralmente pode usar\t\t\t\t\t\t\t\t\t\t\t\tpara eliminar os tempor\u00E1rios. Uma longa lista de par\u00E2metros pode ser reduzida com \t\t\t\t\t\t\t\t\t\t\t\t\te \t\t\t\t\t\t\t\t\t\t\t\t.");
		styledText_3.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_3.setEnabled(false);
		styledText_3.setJustify(true);
		styledText_3.setDoubleClickEnabled(false);
		styledText_3.setBounds(61, 594, 837, 107);
		formToolkit.adapt(styledText_3);
		formToolkit.paintBordersFor(styledText_3);
		
		StyledText styledText_4 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_4.setText("\t\tSe voc\u00EA tentou isso, e ainda tem muitos tempor\u00E1rios e par\u00E2metros, \u00E9 hora de trazer a artilharia pesada:\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.");
		styledText_4.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_4.setEnabled(false);
		styledText_4.setJustify(true);
		styledText_4.setDoubleClickEnabled(false);
		styledText_4.setBounds(61, 707, 837, 46);
		formToolkit.adapt(styledText_4);
		formToolkit.paintBordersFor(styledText_4);
		
		StyledText styledText_5 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_5.setText("\t\tComo identificar as partes do c\u00F3digo para extrair? Uma boa t\u00E9cnica \u00E9 procurar por coment\u00E1rios. Eles normalmente sinalizam esse tipo de dist\u00E2ncia sem\u00E2ntica. Um bloco de c\u00F3digo com um coment\u00E1rio que lhe diz o que est\u00E1 fazendo pode ser substitu\u00EDdo por um m\u00E9todo cujo nome \u00E9 baseado no coment\u00E1rio, o outro que o descreva melhor. Vale a pena extrair at\u00E9 mesmo uma \u00FAnica linha se esta precisa de explica\u00E7\u00E3o.");
		styledText_5.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_5.setEnabled(false);
		styledText_5.setJustify(true);
		styledText_5.setDoubleClickEnabled(false);
		styledText_5.setBounds(61, 759, 837, 89);
		formToolkit.adapt(styledText_5);
		formToolkit.paintBordersFor(styledText_5);
		
		StyledText styledText_6 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_6.setText("\t\tCondicionais e la\u00E7os tamb\u00E9m d\u00E3o sinais para extra\u00E7\u00E3o. Use\t\t\t\t\t\t\t\t\t\t\t\tpara lidar com express\u00F5es condicionais. Com la\u00E7os, extraia o la\u00E7o e o c\u00F3digo dentro do la\u00E7o para o seu pr\u00F3prio m\u00E9todo.");
		styledText_6.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_6.setEnabled(false);
		styledText_6.setJustify(true);
		styledText_6.setDoubleClickEnabled(false);
		styledText_6.setBounds(61, 855, 837, 69);
		formToolkit.adapt(styledText_6);
		formToolkit.paintBordersFor(styledText_6);
		scrolledComposite.setContent(composite_3);
		scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmUsage = new TabItem(tabFolder, SWT.NONE);
		tbtmUsage.setText("Exemplo");
		
		ScrolledComposite scrolledComposite_1 = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmUsage.setControl(scrolledComposite_1);
		formToolkit.paintBordersFor(scrolledComposite_1);
		scrolledComposite_1.setExpandHorizontal(true);
		scrolledComposite_1.setExpandVertical(true);
		
		Composite composite = new Composite(scrolledComposite_1, SWT.NONE);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		scrolledComposite_1.setContent(composite);
		scrolledComposite_1.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmVideo = new TabItem(tabFolder, SWT.NONE);
		tbtmVideo.setText("Video");
		
		Browser browser = new Browser(tabFolder, SWT.NONE);
		browser.setUrl("");
		tbtmVideo.setControl(browser);
		formToolkit.paintBordersFor(browser);
	}
}
